<?php require("inc/common.inc.php");
$web_title="WIFI用户认证";
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
if ($actions=="setren"){
	$rentype=intval($rentype);
	//验证来路
	$truepath=preg_replace("/(.+)\/([^\/]+)\/([^\/]+)/is","\\1",'http://'.$HTTP_HOST);
	if ($webdb[weburl]!=$truepath){
		$fun->popmassage("非法访问，系统将返回上一页","","popback");
		exit();
	}
	$mac=trim($mac);
	$Rid=intval($Rid);
	if($Rid==0 or $mac=="" or strlen($mac)!=12){
		$fun->popmassage("非法访问，系统将返回上一页","","popback");
		exit();
	}
	
	if ($rentype==1){
		$mobile=trim($mobile);
		$mac=trim($mac);
		$Rid=intval($Rid);
		$ycode=trim($ycode);
		//是否为空
		if($mobile==""){
			$fun->popmassage("请输入手机号码","","popback");
			exit();
		}
		//验证手机号格式
		if(!eregi("^[0-9]{11,11}$",$mobile)){
			$fun->popmassage("输入手机号码格式错误","","popback");
			exit();
		}
		if($ycode==""){
			$fun->popmassage("请输入手机验证码","","popback");
			exit();
		}

		$getstatus=file_get_contents($VPPWIFIURL."wifirenzheng_mx_get.php?rentype=1&mobile=$mobile&mac=$mac&Rid=$Rid&shang={$VPPWIFISHANG}&yancode=$ycode&sign=".md5($mac."{mx}".$VPPWIFISHANG."{z}".$mobile."{w}".$Rid."{w}".$ycode."{w}"));
		if($getstatus=="1"){
			$fun->popmassage("手机验证成功",$webdb[weburl],"alertgotourl");
			exit();
		}
		else{
			$fun->popmassage("手机号码验证失败","","popback");
			exit();
		}
	}
	elseif($rentype==2){
		$mac=trim($mac);
		$Rid=intval($Rid);
		$ycode=trim($ycode);
		if($ycode==""){
			$fun->popmassage("请输入微信验证码","","popback");
			exit();
		}

		$getstatus=file_get_contents($VPPWIFIURL."wifirenzheng_mx_get.php?rentype=2&mac=$mac&Rid=$Rid&shang={$VPPWIFISHANG}&yancode=$ycode&sign=".md5($mac."{mx}".$VPPWIFISHANG."{z}{w}".$Rid."{w}".$ycode."{w}"));
		if($getstatus=="1"){
			$fun->popmassage("微信验证成功",$webdb[weburl],"alertgotourl");
			exit();
		}
		else{
			$fun->popmassage("微信验证失败","","popback");
			exit();
		}
	}
//	elseif($rentype==3){
//		$mac=trim($mac);
//		$Rid=intval($Rid);
//		$username=trim($username);
//		$password=trim($password);
//		if($username==""){
//			$fun->popmassage("请输入用户名","","popback");
//			exit();
//		}
//		if($password==""){
//			$fun->popmassage("请输入密码","","popback");
//			exit();
//		}
//
//		$getstatus=file_get_contents($VPPWIFIURL."wifirenzheng_mx_get.php?rentype=3&mac=$mac&Rid=$Rid&shang={$VPPWIFISHANG}&username=$username&password=$password&sign=".md5($mac."{mx}".$VPPWIFISHANG."{z}{w}".$Rid."{w}".$username."{w}"));
//		if($getstatus=="1"){
//			$fun->popmassage("登录验证成功",$webdb[weburl],"alertgotourl");
//			exit();
//		}
//		else{
//			$fun->popmassage("用户名或密码错误","","popback");
//			exit();
//		}
//	}
	elseif($rentype==999){
		$mac=trim($mac);
		$Rid=intval($Rid);
		if($mac=="" or $Rid==0){
			$fun->popmassage("非法访问","","popback");
			exit();
		}

		$getstatus=file_get_contents($VPPWIFIURL."wifirenzheng_mx_get.php?rentype=999&mac=$mac&Rid=$Rid&shang={$VPPWIFISHANG}&sign=".md5($mac."{mx}".$VPPWIFISHANG."{z}{w}".$Rid."{w}"));
		if($getstatus=="1"){
			$fun->popmassage("登录验证成功",$webdb[weburl],"alertgotourl");
			exit();
		}
		else{
			$fun->popmassage("认证失败","","popback");
			exit();
		}
	}
	else{
		$fun->popmassage("非法的认证","","popback");
		exit();
	}
}
?>
<meta content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" name="viewport"> 
<title>WIFI用户认证-<?php echo $webdb['vpp_jigoucode'];?></title>
<link href="images/style.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" src="js/jquery_min.js"></script>
<script>
function get_yancode(){
	var mobile = document.form1.mobile.value;
	if (document.form1.mobile.value==""){
		alert("请输入手机号码");
		return false;
	}
	
	var patrn = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/; 
	if (!patrn.exec(mobile)) {
		alert ('手机号码格式不正确');
		document.form1.mobile.focus();
		return false;
	}
	
	timedCount();
	$.ajax({
    url: '/wifirenzheng.php?rentype=1&mac=<?php echo $mac;?>&Rid=<?php echo $Rid;?>&mobile='+mobile,
    type: 'GET',
    dataType: 'html',
    timeout:15000,
    error: function(){
        c=Time;
        stopCount();
        document.getElementById('getcode').value="获取验证码";
        document.getElementById('getcode').removeAttribute("disabled");
        alert('获取验证码失败');
    },
    success: function(html){
        if (html!="1"){	
			c=Time;
			stopCount();
			document.getElementById('getcode').value="获取验证码";
			document.getElementById('getcode').removeAttribute("disabled");
            alert('获取验证码失败');
        }
    }});
	
}
</script>
<body>
<?php
$head_hide=1;
require("w_head.php");
//判断是否是漫游用户
$ismanyou=file_get_contents($VPPWIFIURL."wifirenzheng_mx_get.php?rentype=99&mac=$mac&Rid=$Rid&shang={$VPPWIFISHANG}&sign=".md5($mac."{mx}".$VPPWIFISHANG."{z}{w}".$Rid."{w}"));
if ($ismanyou=="1"){
?>
<table width="90%" cellpadding="1" cellspacing="1" align="center" bgcolor="#CCCCCC">
	<tr bgcolor="#ededed"><td height="30" align="center" colspan="2"><b>已认证用户，可以直接使用WIFI网络。</b></td></tr>
	<tr bgcolor="#ededed"><td height="30" align="center" colspan="2"><a href="renzheng.php?actions=setren&rentype=999&mac=<?php echo $mac;?>&Rid=<?php echo $Rid;?>">马上链接WIFI</a></td></tr>
</table>
<?php
}else{
?>
<table width="90%" cellpadding="1" cellspacing="1" align="center" bgcolor="#CCCCCC">
	<form name="form1" id="form1" action="renzheng.php" method="post" onSubmit="return check_form1()">
	<tr bgcolor="#ededed"><td height="30" align="center" colspan="2"><b>手机验证</b></td></tr>
	<tr bgcolor="#FFFFFF"><td width="20%" align="center" height="30">手机号码：</td><td width="80%"><input type="text" name="mobile" id="mobile">&nbsp;<input type="button" name="getcode" id="getcode" value="获取验证码" onClick="get_yancode();"></td></tr>
	<tr bgcolor="#FFFFFF"><td align="center" height="30">验&nbsp;证&nbsp;码：</td><td><input type="text" name="ycode" id="ycode"></td></tr>
	<tr bgcolor="#FFFFFF"><td align="center" height="30" colspan="2">
	<input type="submit" name="s" id="s" value="提交认证">
	<input type="hidden" name="mac" id="mac" value="<?php echo trim($mac);?>">
	<input type="hidden" name="Rid" id="Rid" value="<?php echo trim($Rid);?>">
	<input type="hidden" name="rentype" value="1">
	<input type="hidden" name="actions" value="setren">
	</td></tr>
	</form>
</table>
<script>
function check_form1(){
	if (document.form1.mobile.value==""){
		alert("手机号码不能为空");
		document.form1.mobile.focus();
		return false;
	}
	if (document.form1.ycode.value==""){
		alert("验证码不能为空");
		document.form1.ycode.focus();
		return false;
	}
}

    var Time=30,t;
    var c=Time
    function timedCount(){
        document.getElementById('getcode').value="请稍等(" + c + ")";
        document.getElementById('getcode').disabled="disabled";
        c=c-1;
        t=setTimeout("timedCount()",1000)
        if(c<0){
            c=Time;
            stopCount();
            document.getElementById('getcode').value="获取验证码";
            document.getElementById('getcode').removeAttribute("disabled");
        }
    }
    function stopCount(){
        clearTimeout(t);
    }
</script>

<table width="90%" cellpadding="1" cellspacing="1" align="center"  bgcolor="#CCCCCC" style="margin-top:30px;">
	<form name="form2" id="form2" action="renzheng.php" method="post" onSubmit="return check_form2()">
	<tr bgcolor="#ededed"><td height="30" align="center" colspan="2"><b>微信验证</b></td></tr>
	<tr bgcolor="#FFFFFF"><td align="center" height="30">验证码：</td><td><input type="text" name="ycode" id="ycode"></td></tr>
	<tr bgcolor="#FFFFFF"><td align="center" height="30" colspan="2">
	<input type="submit" name="s" id="s" value="提交认证">
	<input type="hidden" name="mac" id="mac" value="<?php echo trim($mac);?>">
	<input type="hidden" name="Rid" id="Rid" value="<?php echo trim($Rid);?>">
	<input type="hidden" name="rentype" value="2">
	<input type="hidden" name="actions" value="setren">
	</td></tr>
	</form>
</table>

<script>
function check_form2(){
	if (document.form2.ycode.value==""){
		alert("验证码不能为空");
		document.form2.ycode.focus();
		return false;
	}
}
</script>



<!--<table width="90%" cellpadding="1" cellspacing="1" align="center" bgcolor="#CCCCCC">
	<form name="form3" id="form3" action="renzheng.php" method="post" onSubmit="return check_form3()">
	<tr bgcolor="#ededed"><td height="30" align="center" colspan="2"><b>用户名登录</b></td></tr>
	<tr bgcolor="#FFFFFF"><td width="20%" align="center" height="30">用户名：</td><td width="80%"><input type="text" name="username" id="username"></td>
	</tr>
	<tr bgcolor="#FFFFFF"><td align="center" height="30">密&nbsp;&nbsp;码：</td><td><input type="password" name="password" id="password"></td></tr>
	<tr bgcolor="#FFFFFF"><td align="center" height="30" colspan="2">
	<input type="submit" name="s" id="s" value="提交登录">
	<input type="hidden" name="mac" id="mac" value="<?php //echo trim($mac);?>">
	<input type="hidden" name="Rid" id="Rid" value="<?php //echo trim($Rid);?>">
	<input type="hidden" name="rentype" value="3">
	<input type="hidden" name="actions" value="setren">
	</td></tr>
	</form>
</table>
<script>
function check_form3(){
	if (document.form3.username.value==""){
		alert("用户名不能为空");
		document.form3.username.focus();
		return false;
	}
	if (document.form3.password.value==""){
		alert("密码不能为空");
		document.form3.password.focus();
		return false;
	}
}
</script>-->
<?php
}

require("w_copyright.php");?>
</body>
</html>
